﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>


<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/enterpriseLayout/makePlan.css" rel="stylesheet" />
    <link href="../assets/css/enterpriseLayout/subCategoryWidthSatisfy.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <style>
        .left-part {
            width: 387px;
        }

        .right-part {
            width: calc(100% - 387px);
            height:100%;
        }

        .left-part .tb-body-container .loadTable tr {
            cursor: pointer;
        }
        .system-box .right-side .btns-part { padding-top:20px;
        }
        .system-box .right-side .btns-part .btns-container {
            border:none;
        }
        .condition-box {width:430px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">

            <div class="left-part">
                <div class="p-title">店铺信息</div>
                <div class="conditions">

                    <div class="condition">
                        <div class="pull-left text-center">
                            <h4 style="line-height: 22px;">选择范围：</h4>
                        </div>
                        <div class=" i-checks">
                            <label>
                                <input type="radio" class="CountryAreaCity" name="CountryAreaCity" checked="checked" value="0" />
                                全国</label>
                        </div>
                        <div class=" i-checks">
                            <label>
                                <input type="radio" class="CountryAreaCity" name="CountryAreaCity" value="1" />
                                区域</label>
                        </div>
                        <div class=" i-checks">
                            <label>
                                <input type="radio" class="CountryAreaCity" name="CountryAreaCity" value="2" />
                                店铺</label>
                        </div>
                    </div>
                    <div class="condition">
                        <label>年月：</label>
                        <input name="search-date" placeholder="年月" class="form-control layer-date  input-w110" id="search-date" />
                        <label>商品区域：</label>
                        <select class="form-control input-w110" id="search-ParentAreaID" disabled="disabled">
                            <option value="">全部</option>
                        </select>
                    </div>
                    <div class="condition">
                        <label>店铺：</label>
                        <input type="text" class="form-control input-w170" placeholder="店铺代码或名称" style="width: 257px !important;" id="search-shop" disabled="disabled" />
                        <button type="button" class="btn btn-primary btn-sm " style="width: auto" id="search-btn-left" disabled="disabled"><i class="fa fa-search"></i></button>
                    </div>
                </div>

                <div style="overflow: auto; overflow-x: hidden; background: #fff;">
                    <div class="tb-head-container" id="thc1">
                        <table class="loadTable">
                            <thead></thead>
                        </table>
                    </div>
                    <div class="tb-body-container" id="tbc1">
                        <table class="loadTable">
                            <tbody class="loadList">
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
            <div class="right-part" style="overflow: hidden; position: relative;">
                <div class="p-title">企划结果汇总</div>
                <div class="conditions clearfix" style="border-bottom: 1px solid rgb(223, 223, 221)">
                    <div class="pull-left text-center">
                        <h4 style="line-height: 55px;">&nbsp;&nbsp;统计方式：</h4>
                    </div>
                    <div class="condition-box pull-left" >
                        <div class="condition">
                            <div class=" i-checks">

                                <label>
                                    <input type="checkbox" class="dataField" name="filter-weekv" id="filter-Weekv" value="Weekv" data-field="周" />
                                    周</label>
                            </div>

                        </div>
                        <div class="condition">
                            <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-SeriesID" id="filter-SeriesID" value="SeriesName" data-field="系列" />
                                    系列</label>
                            </div>
                            <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-MaterialProperty" id="filter-MaterialProperty" value="MaterialProperty" data-field="商品层" />
                                    商品层</label>
                            </div>
                             <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-ModelID" id="filter-ModelID" value="ModelName" data-field="品类" />
                                    品类</label>
                            </div>
                            <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-ItemID" id="filter-ItemID" value="ItemName" data-field="小品类" />
                                    小品类</label>
                            </div>
                            <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-DeepQty" id="filter-DeepQty" value="DeepQty" data-field="总深度" />
                                    深度</label>
                            </div>
                            <div class=" i-checks">
                                <label>
                                    <input type="checkbox" class="dataField" name="filter-PriceColorName" id="filter-PriceColorName" value="PriceColorName" data-field="价格带" data-isnum="1" />
                                    价格带</label>
                            </div>


                        </div>
                     
                    </div>
                       <div class="btns-part pull-left text-center ">
                            <div class="btns-container"></div>
                        </div>
                </div>
                <div style="background: #fff; overflow: hidden; padding: 0 2px;">
                    <div class="scollbody" style="overflow-x: auto;">

                        <div class="tb-head-container" id="thc2">
                            <table class="loadTable">
                                <thead></thead>
                            </table>
                        </div>

                        <div class="tb-body-container" id="tbc2">
                            <table class="loadTable">
                                <tbody class="loadList"></tbody>
                            </table>

                        </div>
                    </div>

                    <div id="stpc2"  >
                        <div class="pageControl"></div>
                    </div>


                </div>
            </div>
            <div class="cb"></div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/numeraljs/numeral.min.js"></script>
    <script src="../assets/js/plugins/linq/jquery.linq.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script>
        $(document).ready(function () {
            //自动收缩左边菜单栏
            commonUtil.autoLeftWidth();
            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", })
            var ModuleID = Y.getUrlParam("ModuleID");
            //绑定筛选条件数据
            commonUtil.bindDwGlobalVariables({ dictValue: '商品区域' }, ['#search-ParentAreaID']);
            commonUtil.bindGetDropDownList(['#search-KindID'], 1); //1 - 类别;
            commonUtil.bindGetDropDownList(['#search-SeriesID'], 2);// 2 - 系列;
            commonUtil.bindGetDropDownList(['#search-MaterialProperty'], 3);// 3- 商品层;
            commonUtil.bindGetDropDownList(['#search-ModelID'], 4);// 4- 品类;
            //获取按钮
            commonUtil.loadBtnList(ModuleID, function () { });
            //初始化日期
            //var planMonth = {
            //    elem: "#search-date",
            //    format: "YYYY-MM",
            //    min: "2015-12",
            //    max: "2099-12",
            //    istime: true,
            //    istoday: false
            //};
            //laydate(planMonth);

            $('#search-date').datepicker({
                format: "yyyy-mm",
                startView: 1,
                minViewMode: 1,
                language: "zh-CN",
                autoclose: true
            });

            Y.API2('PLBasSalePlan', 'GetWeekByYearAndMonth', {}, function (data) {
                if (!Y.checkNull(data) && data.Success!=false) {
                    $.each(data, function (i, item) {
                        $('#search-date').val(item.Yearv + "-" + item.Monthv);
                        $('#search-date').datepicker("update");
                    });
                }
            });
            //初始化表头(左侧)
            tableControl.initThead('#thc1', [{
                trClass: '', children: [
                    { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:46px;">', tdId: '', tdClass: 'hide diy-td-w46' },
                    { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:160px;">区域/店铺</span>', tdId: '', tdClass: 'diy-td-w160' },
                    { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">企划金额</span>', tdId: '', tdClass: 'diy-td-w120' },
                    { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">SKC汇总</span>', tdId: '', tdClass: 'diy-td-w100' },
                ]
            }])

            //获取浏览器类型
            var sUserAgent = navigator.userAgent.toLowerCase();

            //计算容器大小
            var calcContainer = function () {
             
                //计算表格高度
                $('#tbc1').height(
                    $('.right-side').height() - $('.left-part .conditions').outerHeight(true) - $('#thc1').outerHeight(true) - $('.left-part .p-title').outerHeight(true));
                //  console.log($('.right-part .conditions').outerHeight())
                $('#tbc2').height(
                    $('.right-side').height() - $('.pageControl').outerHeight() - $('.right-part .conditions').outerHeight() - $('#thc1').outerHeight() - $('.right-part .p-title').outerHeight() - (sUserAgent.indexOf('chrome') > -1 ? 10 : 17));
                $("#stpc2").height($(".pageControl").outerHeight(true));
                //表格body宽
                $(".right-part .tb-body-container").width($(".right-part .tb-head-container .loadTable").width() + 1);
            }

            var year = '';
            var month = '';
            var week = '';
            var kindID = '';
            var seriesID = '';
            var materialProperty = '';
            var itemID = '';
            var mqq = 0;
            var giveupList = {};
            var headList = [];
            commonUtil.bindWeekItem(['#search-week'], function (els, data) {
                if (data && data.length > 0) {
                    year = data[0].Yearv;
                    month = data[0].Monthv;
                }
            })

            //加载左侧列表
            var loadLeftList = function () {
                $('#tbc1 .loadTable tbody').empty();
                //  layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                var ParentAreaId = $('#search-ParentAreaID').val();
                var YearMonth = $('#search-date').val();
                var Shop = $('#search-shop').val().trim().replace(/'/g, '');
                var CountryAreaCity = $("input[name='CountryAreaCity']:checked").val();
               //console.log(CountryAreaCity);
                Y.API2('PLItemSkcForPC', 'GetPLItemSkcForPCShopList', {
                    ParentAreaID: ParentAreaId,
                    YearMonth: YearMonth,
                    CountryAreaCity: CountryAreaCity,
                    Keys: Shop,
                    Page: 1,
                    Size: 999
                }, function (data) {
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        layer.closeAll('dialog');
                        var tBody = [];

                        if (!Y.checkNull(data)) {
                            data.map(function (item, i) {
                                var name = "";
                                if (CountryAreaCity == 1) name = item.ParentAreaName;
                                else if (CountryAreaCity == 2) name = item.ShopName;

                                var tempTr = {
                                    trClass: i % 2 == 0 ? '' : 'footable-odd',
                                    children: [
                                      //  ParentAreaName
                                        { tdText: '', c: 0, r: 0, tdHtml: '<input type="text" class="shopIdOrParentAreaId" value="' + (item.ShopID || item.ParentAreaID) + '" />', tdId: '', tdClass: 'hide diy-td-w88' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:160px;">' + name + '</span>', tdId: '', tdClass: 'diy-td-w160' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">' + (item.SumPrice || 0) + '</span>', tdId: '', tdClass: 'diy-td-w120' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + (item.SumSKC || 0) + '</span>', tdId: '', tdClass: 'diy-td-w100' },
                                    ]
                                };
                                if (!Y.checkNull(name))
                                    tBody.push(tempTr);
                            })
                            tableControl.initTbody('#tbc1 .loadTable', (tBody.length > 0 ? tBody : null), 0, null);
                            calcContainer();
                            return false;
                        } else {
                            $('#tbc1 .loadList').append(
                            '<tr><td style="width:' + $('#thc1 th:first').width() + 'px;"><i class="fa fa-frown-o"></i></td>' +
                            '<td style="width:' + ($('#thc1 .loadTable').width() - $('#thc1 th:first').width()) + 'px;">无数据</td></tr>');
                        }
                        calcContainer();
                    }
                })
            }


            var fieldArr = []; // 字段数组

            var dataList = [];
            var conditionsArr = [];
            //加载右侧列表
            var loadRightList = function () {
                giveupList = {};
                headList = [];
                if (!initParam(true)) return;
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                pageControlBindElIn.init('PLItemSkcForPC', 'GetPLItemSkcForPCList', {
                    YearMonth: pageControlBindElIn.param.YearMonth,
                    ShopID: pageControlBindElIn.param.ShopID,
                    ParentAreaID: pageControlBindElIn.param.ParentAreaID,
                    CountryAreaCity: pageControlBindElIn.param.CountryAreaCity,
                    isWeek: pageControlBindElIn.param.isWeek,
                    isSeries: pageControlBindElIn.param.isSeries,
                    isMaterialProperty: pageControlBindElIn.param.isMaterialProperty,
                    isModel: pageControlBindElIn.param.isModel,
                    isItem: pageControlBindElIn.param.isItem,
                  
                    isDeep: pageControlBindElIn.param.isDeep,
                    isPrice: pageControlBindElIn.param.isPrice,
                    Page: 1,
                    Size: 50,
                    BindEl: '#stpc2',
                    //alwaysCallBack: function () {
                    //    alert(2)
                    //    initParam();
                    //}

                }, function (result) {

                    var data = result.data;
                    layer.closeAll('dialog');
                    if (result.Success == false) {
                        swal(result.Message, '', 'error');
                    } else {
                        //清空原有数据
                        $('#tbc2 .loadTable tbody').empty();
                        inithead();
                        var hasDeepQty = false;//判断是否存在深度并且不存在价格带 特殊处理
                        var hasPriceColorName = false;
                        fieldArr = [];
                        $(".dataField:checked").each(function (k, obj) {
                            fieldArr.push($(this).val());
                            if ($(this).val() == "DeepQty") hasDeepQty = true;
                            if ($(this).val() == "PriceColorName") hasPriceColorName = true;
                        });

                        //加载数据
                        var tBody = [];
                        if (!Y.checkNull(data)) {


                            if (hasDeepQty && !hasPriceColorName)//存在深度并且不存在价格带情况下 由于返回的数据没有处理成分组，在这里特殊针对处理分组
                            {
                                var groupField = $.Enumerable.From(fieldArr).Where("$!='DeepQty'&&$!='ItemName'").Select("$+':$.'+$").ToString(",");

                                var groupFieldSelect = $.Enumerable.From(fieldArr).Where("$!='DeepQty'&&$!='ItemName'").Select("'$.'+$").ToString(" + '-'+ ");
                                var whereField = $.Enumerable.From(fieldArr).Where("$!='DeepQty'&&$!='ItemName'").Select("'f.'+$+'==x.'+$").ToString("&&");
                                if (!Y.checkNull(groupFieldSelect)) {
                             
                                    var tempList = [];
                                    $.Enumerable.From(data.Items).ForEach(function (x) {
                                        tempList.push(x[0]);
                                    });
                                    //   console.log(tempList);
                                    data.Items = [];
                                    var groupList = $.Enumerable.From(tempList).GroupBy("{" + groupField + "}", null,
                                     "{" + groupField + ",accounting:$$.Sum('($.SumPrice||0)')}"
                                      , groupFieldSelect).ForEach(function (x, index) {
                                          var tt = [];
                                          data.Items[index] = [];
                                          var g = $.Enumerable.From(tempList).Where(function (f, j) {
                                              //  console.log(eval(whereField));
                                              return eval(whereField);
                                          }).ForEach(function (y, j) {
                                              data.Items[index][j] = y;
                                              // x[j]=y;
                                              //  console.log(y);
                                          });
                                          // console.log(x);
                                      });
                                
                                }
                            }

                            dataList = data.Items;
                            if (!Y.checkNull(data.Items) && data.Items.length > 0) {
                                data.Items.map(function (item, i) {
                                    var groupClass = "groupClass" + i;

                                    item.map(function (item2, j) {

                                        var tempChild = [];
                                        $(".dataField:checked").each(function (k, obj) {
                                            var field = $(this).val();
                                            var lastField = $(".dataField:checked:last").val();
                                 
                                            if (field == "ItemName" && hasDeepQty && !hasPriceColorName)//判断是否存在深度并不存在价格带 特殊处理 小品类不需要合并
                                            {
                                                tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + item2[field] + '</span>', tdId: '', tdClass: 'diy-td-w100 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });
                                            } else if (j == 0 && lastField != field) {

                                                tempChild.push({ tdText: '', c: 0, r: item.length, tdHtml: '<span style="display:inline-block; width:100px;">' + item2[field] + '</span>', tdId: '', tdClass: 'diy-td-w100 border-bottom-bold' });
                                            }
                                            //  PriceColorName

                                            if (lastField == field)//最后一个字段都显示
                                            {
                                                var v = item2[field];
                                                if (field == "PriceColorName")//价格带要处理小数点
                                                {
                                                  v=  Y.formatZero(numeral(v).format("0.00"));
                                                }
                                                tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + v+ '</span>', tdId: '', tdClass: 'diy-td-w100 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });
                                            }
                                        });

                                        tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">' + Y.formatZero(numeral(item2.SumPrice).format("0.00")) + '</span>', tdId: '', tdClass: 'diy-td-w120 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });
                                        tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + (item2.SumSKC || '0') + '</span>', tdId: '', tdClass: 'diy-td-w100 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });
                                        tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;" data-index="' + j + '" class="calcAmount">0</span>', tdId: '', tdClass: 'diy-td-w100 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });

                                        var tempTr = {
                                            trClass: groupClass,
                                            children: tempChild
                                        };
                                        tBody.push(tempTr);


                                    });
                                });

                                tableControl.initTbody('#tbc2 .loadTable', (tBody.length > 0 ? tBody : null), 12, null);
                                calcAmount();
                            }
                            else {

                                var thc = $("#thc2");
                                $('#tbc2 .loadTable').append(
                      '<tr><td style="width:' + thc.find('th:first').width() + 'px;"><i class="fa fa-frown-o"></i></td>' +
                      '<td style="width:' + (thc.find('.loadTable').width() - thc.find('th:first').width()) + 'px;">无数据</td></tr>');
                            }
                        }


                        calcContainer();
                    }
                })
            }
            //条件参数 统一方法 分页时改变参数也改变
            function initParam(check) {

                //alert($("#filter-Weekv:checked").val());
                //alert($("#filter-Weekv").prop('checked'));
                var YearMonth = $("#search-date").val().trim().replace(/'/g, '');
                var MaterialProperty = $("#search-date").val().trim().replace(/'/g, '');
                var CountryAreaCity = $("input[name='CountryAreaCity']:checked").val();
                var isWeek = $("#filter-Weekv").prop('checked');
                var isSeries = $("#filter-SeriesID").prop('checked');
                var isMaterialProperty = $("#filter-MaterialProperty").prop('checked');
                var isModel = $("#filter-ModelID").prop('checked');
                var isItem = $("#filter-ItemID").prop('checked');
             
                var isDeep = $("#filter-DeepQty").prop('checked');
                var isPrice = $("#filter-PriceColorName").prop('checked');
                var shopIdOrParentAreaId = $('#tbc1 tr.check').find("input.shopIdOrParentAreaId").val();
                var verify = false;
                if (isSeries || isMaterialProperty || isModel|| isItem || isDeep || isPrice ) {
                    verify = true;
                }
                if (!verify&&check) {
                    swal('至少选择一个统计方式');

                    return false;
                }  
             
             
              //查询按钮设置 禁用
                if (Y.checkNull(shopIdOrParentAreaId) && CountryAreaCity != 0) {
                    $("#btn-search").attr("disabled", true);
                } else {
                    $("#btn-search").attr("disabled", false);
                }


                // console.log($(".dataField:checked").val());

            
                var ShopID = "", ParentAreaID = "";
                if (CountryAreaCity == 2) {
                    ShopID = shopIdOrParentAreaId;
                } else if (CountryAreaCity == 1) {
                    ParentAreaID = shopIdOrParentAreaId;
                }
              
                pageControlBindElIn.param.YearMonth=YearMonth ;
                pageControlBindElIn.param.ShopID = ShopID;
                pageControlBindElIn.param.ParentAreaID = ParentAreaID;
                pageControlBindElIn.param.CountryAreaCity = CountryAreaCity;
                pageControlBindElIn.param.isWeek = isWeek;
                pageControlBindElIn.param.isSeries = isSeries;
                pageControlBindElIn.param.isMaterialProperty = isMaterialProperty;
                pageControlBindElIn.param.isModel = isModel;
                pageControlBindElIn.param.isItem = isItem;
                pageControlBindElIn.param.isDeep = isDeep;
                pageControlBindElIn.param.isPrice = isPrice;
                return true;
            }

            calcContainer();
            $(window).resize(function () {
                //重新计算容器高度
                calcContainer();
            })
            //占比计算
            var calcAmount = function () {
                //var lastField = $(".dataField:checked:last").val();

                var linqData = $.Enumerable.From(dataList);
                //var groupField = $.Enumerable.From(fieldArr).Select("$+':$.'+$").ToString(",");
                //var groupFieldSelect = $.Enumerable.From(fieldArr).Select("'$.'+$").ToString(" + '-'+ ");
                linqData.ForEach(function (x, i) {

                    var SumPriceTotal = $.Enumerable.From(x).Sum("($.SumPrice||0)");
                    // console.log(SumPriceTotal);
                    $.Enumerable.From(x).ForEach(function (y, j) {
                        var accounting = numeral(y.SumPrice || 0).divide(SumPriceTotal).multiply(100).format('0.00');
                        //  console.log(y);
                        $(".groupClass" + i).find("[data-index='" + j + "']").text(accounting);
                    });
                    //    var queryResult = seq.GroupBy("$=>{Yearv:$.Yearv,Monthv:$.Monthv,ParentAreaID:$.ParentAreaID,KindID:$.KindID,SeriesID:$.SeriesID,MaterialProperty:$.MaterialProperty,OldCkPtStandAmountRate:$.OldCkPtStandAmountRate}", null,
                    //"{Yearv:$.Yearv,Monthv:$.Monthv,ParentAreaID:$.ParentAreaID,KindID:$.KindID,SeriesID:$.SeriesID,MaterialProperty:$.MaterialProperty,OldCkPtStandAmountRate:$.OldCkPtStandAmountRate,updateRateSum:$$.Sum('numeral($.PtUpdateRate).divide(100).multiply($.CkPtStandAmountRate).value()')}"
                    // , "$.Yearv + '-'+ $.Monthv + '-'+ $.ParentAreaID + '-'+ $.KindID + '-'+ $.SeriesID + '-'+ $.MaterialProperty").ToArray();//商品层分组结果
                    //      x.GroupBy("{" + groupField + "}", null,
                    //"{" + groupField + ",accounting:$$.Sum('($.SumPrice||0)')/}"
                    //  , groupFieldSelect)
                });
            };
            $('#filter-SeriesID').iCheck('check');
            // inithead();
            //$(document).on('ifChanged', ".dataField", function () {
            //    inithead();
            //})
            function inithead() {
                // if (dataList.length> 0) return;
                var headChildren = [];
                $(".dataField:checked").each(function () {
                    var field = $(this).attr("data-field");
                    headChildren.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + field + '</span>', tdId: '', tdClass: 'diy-td-w100' });
                });
                headChildren.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">企划金额</span>', tdId: '', tdClass: 'diy-td-w120' });
                headChildren.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">SKC汇总</span>', tdId: '', tdClass: 'diy-td-w100' });
                headChildren.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">金额占比%</span>', tdId: '', tdClass: 'diy-td-w100' });
                ////初始化表头

                tableControl.initThead('#thc2 .loadTable', [{
                    trClass: '', children: headChildren
                }]);
            };
            //选择范围 条件控件处理
            $("input[name='CountryAreaCity']").on("ifChanged", function () {
                
                var countryAreaCity = $("input[name='CountryAreaCity']:checked").val();
                $('#tbc1 .loadTable tbody').empty();
                $("#search-ParentAreaID option").eq(0).prop("disabled", false);
                $("#search-ParentAreaID").val("");
                if (countryAreaCity == 1) {
                    $("#search-ParentAreaID").attr("disabled", false);
                    $("#search-btn-left").attr("disabled", false);
                    $("#search-shop").val("");
                    $("#search-shop").attr("disabled", true);
                } else if (countryAreaCity == 2) {
                    $("#search-ParentAreaID").attr("disabled", false);
                    $("#search-btn-left").attr("disabled", false);
                    $("#search-shop").attr("disabled", false);
                    $("#search-ParentAreaID option").eq(0).attr("disabled", true);
                    $("#search-ParentAreaID option").eq(1).prop("selected", true);

                }
                else if (countryAreaCity == 0) {

                    $("#search-ParentAreaID").attr("disabled", true);
                    $("#search-btn-left").attr("disabled", true);
                    $("#search-shop").val("");
                    $("#search-shop").attr("disabled", true);
                }
                //更改条件
                initParam();
            });
            $(document).on('ifChecked', "#filter-DeepQty", function (event) {
                $('#filter-ItemID').iCheck('check');
            });
            $(document).on('ifUnchecked', "#filter-ItemID", function (event) {
                $('#filter-DeepQty').iCheck('uncheck');
            });
            //更改条件
            $(document).on('ifChanged', ".dataField,.CountryAreaCity", function (event) {
                // $('#filter-DeepQty').iCheck('uncheck');
                initParam();
            });
            //更改条件
            $("input[name='search-date'],#search-ParentAreaID,#search-shop").on("change", function () {
                initParam();
            });

           
            //$(document).on('ifUnchecked', "#filter-DeepQty", function (event) {
            //    $('#filter-ItemID').iCheck('uncheck');
            //});

            //查询
            $("#search-btn-left").on("click", function () {
                var date = $("input[name='search-date']").val();
                if (Y.checkNull(date)) {
                    swal('年月必选');
                    return;
                }
                loadLeftList();
            });


            //查询 右边
            $(document).on("click", "#btn-search", function () {
                var date = $("input[name='search-date']").val();
                var shopIdOrParentAreaId = $('#tbc1 tr.check').find("input.shopIdOrParentAreaId").val();
                var countryAreaCity = $("input[name='CountryAreaCity']:checked").val();
                if (Y.checkNull(date)) {
                    swal('年月必选');
                    return;
                }
                if (Y.checkNull(shopIdOrParentAreaId) && countryAreaCity != 0) {
                    swal('请选择区域/店铺');
                    return;
                }
                loadRightList();
            });

            //选中行（左侧）
            $('#tbc1').on('click', 'tr:not(.check) td', function () {
                var tr = $(this).parents('tr');
                if (tr.find("input").length > 0) {
                    $('#tbc1 tr').removeClass('check');
                    tr.addClass('check');
                    //更换条件
                    initParam();
                }
            })
            //导出
            $(document).on("click", "#exportBtn", function () {
                var YearMonth = $("#search-date").val().trim().replace(/'/g, '');
                if (Y.checkNull(YearMonth)) {
                    swal('年月必选');
                    return;
                }
                swal({ title: "确定要导出数据吗?", type: "warning", showCancelButton: true, cancelButtonText: "取消", confirmButtonText: "确定导出", closeOnConfirm: false },
                    function () {
                        //  $.DownloadExcelTemplate("PLITEMSKCFORPC");
                        var conditionsArr = [];
                        //conditionsArr.push({ column: "YearMonth", value: $("#search-ParentAreaId").val().trim().replace(/'/g, ''), operator: "like", connector: "and" });
                        //conditionsArr.push({ column: "ShopCode", value: $("#search-keys").val().trim().replace(/'/g, ''), operator: "like", connector: "and (" });
                        //conditionsArr.push({ column: "ShopName", value: $("#search-keys").val().trim().replace(/'/g, '') + " )", operator: "like", connector: "or" });

                        var CountryAreaCity = $("input[name='CountryAreaCity']:checked").val();
                        var isWeek = $("#filter-Weekv").prop('checked');
                        var isSeries = $("#filter-SeriesID").prop('checked');
                        var isMaterialProperty = $("#filter-MaterialProperty").prop('checked');
                        var isModel = $("#filter-ModelID").prop('checked');
                        var isItem = $("#filter-ItemID").prop('checked');
                        var isDeep = $("#filter-DeepQty").prop('checked');
                        var isPrice = $("#filter-PriceColorName").prop('checked');
                        var ParentAreaId = $('#search-ParentAreaID').val();
                        var Year = $('#search-date').datepicker("getDate").getFullYear();
                        var Month = $('#search-date').datepicker("getDate").getMonth();
                        conditionsArr.push({ column: "Yearv", value: Year, operator: "=", connector: "and" });
                        conditionsArr.push({ column: "Monthv", value: (Month + 1), operator: "=", connector: "and" });
                        if (CountryAreaCity != 0 && !Y.checkNull(ParentAreaId))
                            conditionsArr.push({ column: "pc.ParentAreaID", value: ParentAreaId, operator: "=", connector: "and" });
                        conditionsArr.push({ column: "other.Contions", value: "23", operator: "=", connector: "and" });
                        if (CountryAreaCity == 0) {
                            conditionsArr.push({ column: "isCountry", value: 0, operator: "=", connector: "and" });
                        } else if (CountryAreaCity == 1) {
                            conditionsArr.push({ column: "isArea", value: 1, operator: "=", connector: "and" });
                        }
                        else if (CountryAreaCity == 2) {
                            conditionsArr.push({ column: "isShop", value: 2, operator: "=", connector: "and" });
                        } 
                        if (isWeek)
                            conditionsArr.push({ column: "isWeekv", value: isWeek, operator: "=", connector: "and" });
                        if (isSeries)
                            conditionsArr.push({ column: "isSeries", value: isSeries, operator: "=", connector: "and" });
                        if (isMaterialProperty)
                            conditionsArr.push({ column: "isMaterialProperty", value: isMaterialProperty, operator: "=", connector: "and" });
                        if (isItem)
                            conditionsArr.push({ column: "isItem", value: isItem, operator: "=", connector: "and" });
                        if (isModel)
                            conditionsArr.push({ column: "isModel", value: isModel, operator: "=", connector: "and" });
                        if (isDeep)
                            conditionsArr.push({ column: "isDeep", value: isDeep, operator: "=", connector: "and" });
                        if (isPrice)
                            conditionsArr.push({ column: "isPrice", value: isPrice, operator: "=", connector: "and" });
                        conditionsArr = JSON.stringify(conditionsArr);
                        var tempParam = {};
                        tempParam.filename = "企划结果汇总表";
                        tempParam.filetype = "PLITEMSKCFORPC";
                        tempParam.conditions = encodeURIComponent(conditionsArr);
                        var t = $.Export(tempParam);
                        //console.log(t);
                        swal.close();
                        // swal("Good job!", "You clicked the button!", "success")
                    });
            });

        })
    </script>
</asp:Content>

